﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RestaurantBooker.Web.Data;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace RestaurantBooker.Model
{
    public class FreeTableList : ObservableCollection<Room_Table>, INotifyPropertyChanged
    {
        /// <summary>
        /// The <see cref="TotalFreePlaces" /> property's name.
        /// </summary>
        public const string TotalFreePlacesPropertyName = "TotalFreePlaces";

        private int _totalFreePlaces = 0;

        /// <summary>
        /// Gets the TotalFreePlaces property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public int TotalFreePlaces
        {
            get
            {
                return GetTotalFreePlaces();
            }
        }



        /// <summary>
        /// Return count of the free places
        /// </summary>
        /// <returns></returns>
        private int GetTotalFreePlaces()
        {
            throw new NotImplementedException();
        }

        #region INotifyPropertyChanged
        /// <summary>
        /// Raises the PropertyChanged event if needed.
        /// </summary>
        /// <param name="propertyName">The name of the property that
        /// changed.</param>
        [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate",
            Justification = "This cannot be an event")]
        protected virtual void RaisePropertyChanged(string propertyName)
        {
            VerifyPropertyName(propertyName);

            var handler = PropertyChanged;

            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        /// <summary>
        /// Verifies that a property name exists in this ViewModel. This method
        /// can be called before the property is used, for instance before
        /// calling RaisePropertyChanged. It avoids errors when a property name
        /// is changed but some places are missed.
        /// <para>This method is only active in DEBUG mode.</para>
        /// </summary>
        /// <param name="propertyName"></param>
        [Conditional("DEBUG")]
        [DebuggerStepThrough]
        public void VerifyPropertyName(string propertyName)
        {
            var myType = this.GetType();
            if (myType.GetProperty(propertyName) == null)
            {
                throw new ArgumentException("Property not found", propertyName);
            }
        }

        // ToDo: Test new keyword in event 
        public new event PropertyChangedEventHandler PropertyChanged;
        #endregion
    }
}
